package com.yin.dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Repository;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.yin.entity.UserEntity;

/**
*@author LSY
*Time: 2018年12月24日下午5:07:09
*
*
*/
@Repository(value="userDao")
public class UserDao {

	@Autowired
	private RestTemplate restTemplate;
	
	
	@HystrixCommand(fallbackMethod = "queryUserByIdFallback")
	public UserEntity queryUserById(Long id) {
		String url = "http://user-service/user/"+id;
		
		ResponseEntity<UserEntity> entity = restTemplate.getForEntity(url, UserEntity.class);
		return entity.getBody();
	}
	
	public UserEntity queryUserByIdFallback(Long id) {
		UserEntity entity = new UserEntity();
		entity.setId(id);
		entity.setName("用户信息查询出现异常!");
		return entity;
	}
}
